package com.smu.service;

import com.smu.entity.Girl;
import com.smu.entity.Result;
import com.smu.enums.ResultEnum;
import com.smu.exception.GirlException;
import com.smu.repository.GirlResitory;
import com.smu.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * Created by smwsk
 * 2017/4/4.
 */
@Service
public class GirlService {
    @Autowired
    private GirlResitory girlResitory;
    @Transactional
    public Result getAge(Integer id) throws Exception {
        Girl girl = girlResitory.getOne(id);
        Integer age = girl.getAge();
        if(age<10){
            throw new GirlException(ResultEnum.PRIMARY_SCHOOL);
        }else if (age>10&&age<16){
            throw new GirlException(ResultEnum.MIDDLE_SCHOOL);
        }else{
            return ResultUtil.success(age);
        }
    }
    public Girl getGrilById(Integer id){
        return  girlResitory.findOne(id);
    }
}
